import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:device_verify/device_verify.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _deviceToken = 'Unknown';
  final _deviceVerifyPlugin = DeviceVerify();

  @override
  void initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getDeviceToken() async {
    String deviceToken;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      deviceToken =
          await _deviceVerifyPlugin.getDeviceToken() ?? 'Unknown platform version';
      setState(() {
        _deviceToken = deviceToken;
      });
    } on PlatformException {
      deviceToken = 'Failed to getDeviceToken.';
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              ElevatedButton(
                onPressed: () {
                  getDeviceToken();
                },
                child: const Text("getDeviceToken"),
              ),
              Text(_deviceToken),
            ],
          ),
        ),
      ),
    );
  }
}
